exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
    indexAction() {}

    getOrgsAction() {
        var _this = this;

        return _asyncToGenerator(function* () {
            //根据父id获取所有子部门
            let aj = think.ajaxJson();
            const data = { id: _this.post('org_id') };
            const OrgService = _this.service('api/sys/OrgService');
            const res = yield OrgService.getOrgs(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '机构列表查询错误';
            }
            return _this.json(aj);
        })();
    }

    getAllOrgAction() {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            //获取所有部门列表
            let aj = think.ajaxJson();
            const OrgService = _this2.service('api/sys/OrgService');
            const res = yield OrgService.getAllOrg();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '机构列表获取失败';
            }
            return _this2.json(aj);
        })();
    }

    getUserOrgListAction() {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            //获取可选部门列表，不分层级
            let aj = think.ajaxJson();
            const OrgService = _this3.service('api/sys/OrgService');
            const userData = _this3.getUser();
            const res = yield OrgService.getOrgList(userData);
            if (res && !res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '机构列表获取失败';
            }
            return _this3.json(aj);
        })();
    }

    getUserListByOrgAction() {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            //获取部门下用户列表
            let aj = think.ajaxJson();
            const OrgService = _this4.service('api/sys/OrgService');
            const data = { org_id: _this4.post('org_id') };
            const res = yield OrgService.getUserListByOrg(data);
            if (res && !res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '用户列表获取失败';
            }
            return _this4.json(aj);
        })();
    }

};